 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace lab5
{
    public partial class Form1 : Form
    {
        abstract class Candy
        {
            
            public abstract int kilocalo
            {
                get;
                set;
            }
            public abstract decimal Price
            {
                get;
                set;
            }
            public abstract string Name
            {
                get;
                set;
            }
        }

        class Candy2009 : Candy
        {
            private int _kilocalo;
            private decimal _price;
            private string _name;
            public Candy2009() : this(null) { }
            public Candy2009(string _name) : this(_name, 0) { }
            public Candy2009(string _name, decimal _price) : this(_name, _price, 0) { }
            public Candy2009(string _name, decimal _price, int _kilocalo)
            {
                this._name = _name;
                this._kilocalo = _kilocalo;
                
                this._price = _price;
            }
            public override string Name
            {
                get
                {
                    return _name;
                }
                set
                {
                    _name = value;
                }
            }
            public override int kilocalo
            {
                get
                {
                    return _kilocalo;
                }
                set
                {
                    _kilocalo = value;
                }
            }
            public override decimal Price
            {
                get
                {
                    return _price;
                }
                set
                {
                    _price = value;
                }
            }

        }


        //bo sung them thuoc tinh vao
        class Candy2010 : Candy
        {
            private int _kilocalo;
            private decimal _price;
            private string _name;

            public Candy2010() : this(null) { }
            public Candy2010(string _name) : this(_name, 0) { }
            public Candy2010(string _name, decimal _price) : this(_name, _price, 0) { }
            public Candy2010(string _name, decimal _price, int _kilocalo)
            {
                this._price = _price;
                this._name = _name;
                this._kilocalo = _kilocalo;
              
            }
            public override string Name
            {
                get
                {
                    return _name;
                }
                set
                {
                    _name = value;
                }
            }
            public override decimal Price
            {
                get
                {
                    return _price;
                }
                set
                {
                    _price = value;
                }
            }
            public override int kilocalo
            {
                get
                {
                    return _kilocalo;
                }
                set
                {
                    _kilocalo = value;
                }
            }

        }

        class Candy2011 : Candy
        {
            private string _name;
            private int _kilocalo;
            private decimal _price;
            public Candy2011() : this(null) { }
            public Candy2011(string _name) : this(_name, 0) { }
            public Candy2011(string _name, decimal _price) : this(_name, _price, 0) { }
            public Candy2011(string _name, decimal _price, int _kilocalo) 
            {
                this._name = _name;
                this._kilocalo = _kilocalo;
                this._price = _price;
            }
            public override string Name
            {
                get
                {
                    return _name;
                }
                set
                {
                    _name = value;
                }
            }
            public override int kilocalo
            {
                get
                {
                    return _kilocalo;
                }
                set
                {
                    _kilocalo = value;
                }
            }
            public override decimal Price
            {
                get
                {
                    return _price;
                }
                set
                {
                    _price = value;
                }
            }
          
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void txtLoai_SelectedIndexChanged(object sender, EventArgs e)
        {

          
 
        }
        Candy2009 Eclair = new Candy2009("Eclair", 300, 30);
        Candy2009 HoneyComb = new Candy2009("HoneyComb", 500, 4);
        Candy2010 JellyBean = new Candy2010("JellyBean", 100, 200);
        Candy2011 Kitkat = new Candy2011("Kitkat", 50, 50);
        Candy2011 Lollipop = new Candy2011("Lollipop", 20, 40);
        private void Form1_Load(object sender, EventArgs e)
        {
            txtSoluong.Enabled = false;
            txtGia.Enabled = false;
            txtTen.Enabled = false;
            txtSoLuongGhe.Enabled = false;
           

        }
        bool test = false;
        private void txtLoaicuthe_SelectedIndexChanged(object sender, EventArgs e)
        {
            test = true;
            int selectindex = txtLoaicuthe.SelectedIndex;
            if (selectindex == 0)
            {
                txtTen.Text = Eclair.Name;
                txtSoLuongGhe.Text = Eclair.kilocalo.ToString();
                txtGia.Text = Eclair.Price.ToString();
            }
            else if (selectindex == 1)
            {
                txtTen.Text = HoneyComb.Name;
                txtSoLuongGhe.Text = HoneyComb.kilocalo.ToString();
                txtGia.Text = HoneyComb.Price.ToString();
            }
            else if (selectindex == 2)
            {
                txtTen.Text = JellyBean.Name;
                txtSoLuongGhe.Text = JellyBean.kilocalo.ToString();
                txtGia.Text = JellyBean.Price.ToString();
            }
            else if (selectindex == 3)
            {
                txtTen.Text = Kitkat.Name;
                txtSoLuongGhe.Text = Kitkat.kilocalo.ToString();
                txtGia.Text = Kitkat.Price.ToString();
            }
            else if (selectindex == 4)
            {
                txtTen.Text = Lollipop.Name;
                txtSoLuongGhe.Text = Lollipop.kilocalo.ToString();
                txtGia.Text = Lollipop.Price.ToString();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtSoluong.Enabled = true;
            if (test == false)
            {
                MessageBox.Show("ERROR", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            txtSoluong.Text = null;
        }
        decimal result=0;
        private void btTinhtoan_Click(object sender, EventArgs e)
        {

            result = result + decimal.Parse(txtSoLuongGhe.Text) * decimal.Parse(txtSoluong.Text);
            txtGiatri.Text = result.ToString();
        }

        private void label7_Click(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("'Do You Really Want To Exit?'", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (result == DialogResult.OK)
          this.Close(); // hoặc e.Cancel=true;
        }

        private void txtSoLuongGhe_TextChanged(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Left += 5;
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

       
        
    }
}
